package com.appbee.news.server;

import java.util.List;

import com.appbee.core.server.requestfactory.BaseService;

public class NewsService extends BaseService<News,NewsDAO>
{
	
	public NewsService()
	{
	}

	public NewsListResult findByRange(int start,int size)
	{
		return doFindByRange(start, size,daoProvider.get());
	}
	public NewsListResult doFindByRange(int start,int size,NewsDAO dao)
	{
		int totalCount = totalSize();
		List<News> list = dao.findByRange(start, size);
		NewsListResult result = new NewsListResult();
		result.setList(list);
		result.setTotalCount(totalCount);
		return result;
	}
	
	public NewsListResult publish(News news,int size)
	{
		NewsDAO newsDAO = daoProvider.get();

		newsDAO.saveAllTransaction(news);
		NewsListResult result = doFindByRange(0,size,newsDAO);
		return result;
	}
	
	public Integer totalSize()
	{
		return daoProvider.get().totalSize();
	}
	
	public News findById(long id)
	{
		return daoProvider.get().findById(id);
	}
	
	public News save(News bean)
	{
		daoProvider.get().saveAllTransaction(bean);
		return bean;
	}
	
	public NewsListResult removeAndFindByRange(News bean,int start,int size)
	{
		daoProvider.get().delete(bean);
		return findByRange(start, size);
	}
}
